home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#)srun.c 1.4 97/03/03
- *
- * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the confidential and proprietary information of Sun
- * Microsystems, Inc. ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- * CopyrightVersion 1.0
- */
-
- /*
- * SRUN - ServletRunner for testing servlets on Win32 systems. In order
- * to run the server, a 1.0.2 compatible runtime must be found in the
- * executable search path. The default name of the runtime executable
- * to use is "java.exe" but can be overriden by setting JAVA_EXE.
- */
-
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <process.h>
- #include <direct.h>
-
- #define JAVA_EXE "java.exe"
-
- /*
- * Return true if specified path refers to a directory.
- */
- int isDirectory(char *path)
- {
- int attr = GetFileAttributes(path);
- return (attr != -1) && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
- }
-
- /*
- * Returns true if specified path refers to a file.
- */
- int isFile(char *path)
- {
- int attr = GetFileAttributes(path);
- return (attr != -1) && ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0);
- }
-
- /*
- * Print error message and die.
- */
- void error(char *msg)
- {
- fprintf(stderr, "Fatal error: %s\n", msg);
- exit(1);
- }
-
- void
- main(int argc, char *argv[])
- {
- char *java_exe, *jsdk_home, *cp;
- char **args, **ap;
- char buf[1024];
- int r;
-
- /*
- * JAVA_EXE if set is the file name of the 1.0.2 compatible Java runtime
- * to use when running the server.
- */
- java_exe = getenv("JAVA_EXE");
- if (java_exe == 0) {
- java_exe = JAVA_EXE;
- }
-
- /*
- * JSDK_HOME if set is the directory where the Java Servlet Development
- * Kit (JSDK) was installed. Otherwise, it defaults to the parent of the
- * directory containing this executable.
- */
- jsdk_home = getenv("JSDK_HOME");
- if (jsdk_home == 0) {
- GetModuleFileName(0, buf, sizeof(buf));
- cp = strrchr(buf, '\\') + 1;
- strcpy(cp, "..");
- jsdk_home = strdup(buf);
- }
- if (!isDirectory(jsdk_home)) {
- error("Invalid setting for JSDK_HOME (not a directory).");
- }
-
- /*
- * Add JSDK classes to CLASSPATH.
- */
- cp = getenv("CLASSPATH");
- sprintf(buf, "CLASSPATH=%s\\classes;%s\\lib\\classes.zip;%s",
- jsdk_home, jsdk_home, cp != 0 ? cp : "");
- putenv(strdup(buf));
-
- /*
- * Gather arguments to pass to java.exe
- */
- ap = args = malloc((argc + 2) * sizeof(char *));
- *ap++ = java_exe;
- *ap++ = "sun.servlet.http.HttpServer";
- while (--argc > 0) {
- *ap++ = *++argv;
- }
- *ap = 0;
-
- /*
- * Invoke Java runtime.
- */
- r = spawnvp(P_WAIT, args[0], args);
- if (r != 0) {
- perror(args[0]);
- exit(1);
- }
- }
-